package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone_num      string `gorm:"type:varchar(30);unique;not null;commit:'电话号'"`
	Pwd            string `gorm:"type:varchar(32);not null;commit:'密码'"`
	Nick_name      string `gorm:"type:varchar(50);not null;commit:'昵称'"`
	Avatar_link    string `gorm:"type:varchar(300);commit:'头像'"`
	Register_time  string `gorm:"type:varchar(300);commit:'注册时间'"`
	Account_status int8   `gorm:"type:tinyint;default:0;commit:'账号状态'"`
	Follow_num     int    `gorm:"type:int(11);default:0;commit:'关注数'"`
	Fans_num       int    `gorm:"type:int(11);default:0;commit:'粉丝数'"`
}

func (u *User) FindUserByPhoneNum(db *gorm.DB, num string) error {
	return db.Debug().Where("users.phone_num= ?", num).Find(&u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) ResetPassword(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("users.id= ?", id).Find(&u).Error
}

func (u *User) UpUserMessage(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
